﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace cubeworld
{
    public class FPSCounter
    {
        private int fps;
        private int ups;
        private float fps_elapsedTime;
        private float ups_elapsedTime;
        private int fps_counter;
        private int ups_counter;

        public int FPS
        {
            get { return fps; }
        }
        public int UPS
        {
            get { return ups; }
        }

        public void Update(float elapsedMilliseconds)
        {
            ups_elapsedTime += elapsedMilliseconds;

            if (ups_elapsedTime >= 1000f)
            {
                ups_elapsedTime -= 1000f;

                ups = ups_counter;
                ups_counter = 0;
            }

            ups_counter++;
        }

        public void Draw(float elapsedMilliseconds)
        {
            fps_elapsedTime += elapsedMilliseconds;

            if (fps_elapsedTime >= 1000f)
            {
                fps_elapsedTime -= 1000f;

                fps = fps_counter;
                fps_counter = 0;
            }

            fps_counter++;
        }
    }
}
